import {Injectable} from '@angular/core';
import {BehaviorSubject} from "rxjs";

@Injectable({
  providedIn: 'root'
})
export class AuthService {

  constructor() {
  }

  isLogin: BehaviorSubject<Boolean> = new BehaviorSubject<Boolean>(this.ifLogin());

  getToken() {
    return sessionStorage.getItem('token');
  }

  setToken(token?: string) {
    sessionStorage.setItem('token', token);
    this.isLogin.next(true);
  }

  delToken() {
    sessionStorage.removeItem('token');
    this.isLogin.next(false);
  }

  ifLogin(): Boolean {
    return sessionStorage.getItem("token") != null;

  }
}
